<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS+CSS写一个跟随光标流光的按钮效果</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            user-select: none;
            font-family: 'Poppins', 'sans-serif';
        }
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-color: #222;
            gap: 50px;
            flex-direction: column;
        }
        a {
            position: relative;
            padding: 20px 60px;
            background-color: rgba(45, 45, 45, 1);
            border-radius: 50px;
            color: #999;
            font-size: 1.5em;
            text-decoration: none;
            overflow: hidden;
            transition: .5s;
        }
        a:hover {
            color: var(--clr);
            text-shadow: 0 0 15px var(--clr),
                         0 0 40px var(--clr);
        }
        a::before {
            content: "";
            position: absolute;
            top: var(--y);
            left: var(--x);
            transform: translate(-50%, -50%);
            width: 200px;
            height: 200px;
            background-image: radial-gradient(var(--clr), transparent, transparent);
            opacity: 0;
            transition: all .5s, top 0, left 0;
        }
        a:hover::before {
            opacity: 1;
        }
        a::after {
            content: "";
            background-color: rgba(45, 45, 45, .8);
            position: absolute;
            inset: 2px;
            border-radius: 48px;
        }
        a span {
            position: relative;
            z-index: 1;
            letter-spacing: .2em;
        }
    </style>
</head>
<body>
    <a href="#" style="--clr: #0f0"><span>BUTTON</span></a>
    <a href="#" style="--clr: #ff0"><span>BUTTON</span></a>
    <a href="#" style="--clr: #f0f"><span>BUTTON</span></a>
    <script>
        const a = document.querySelectorAll("a");
        a.forEach(btn => {
            btn.addEventListener("mousemove", (e) => {
                let x = e.pageX - btn.offsetLeft;
                let y = e.pageY - btn.offsetTop;

                btn.style.setProperty("--x", x + "px");
                btn.style.setProperty("--y", y + "px");
            });
        });
    </script>
</body>
</html>
